//
//  LatestAnnouncedVC.m
//  NormalFramework
//
//  Created by beisheng03 on 2018/3/12.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "LatestAnnouncedVC.h"
#import "LatestAnnouncedCell.h"
@interface LatestAnnouncedVC ()
/** <#note#> */
@property (nonatomic, assign) NSInteger remainingTime;

@property (nonatomic, weak) NSTimer *timer;

/** <#note#> */
@property (nonatomic, assign) BOOL reload;
@end

@implementation LatestAnnouncedVC


- (void)viewDidLoad {
    [super viewDidLoad];
    
//    [self.tableView registerNib: forCellReuseIdentifier:[HomeCycleImageCell identifierStr]];
    
    [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([LatestAnnouncedCell class]) bundle:nil] forCellWithReuseIdentifier:[LatestAnnouncedCell identifierStr]];
    
    self.collectionView.backgroundColor = lineGray;
    
    self.remainingTime = 10000;
    
    
    self.timer =[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countdown) userInfo:nil repeats:YES];
    [self.timer fire];
    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];

    
}



- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    [self.collectionView reloadData];
    
    self.reload = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    
    self.reload = NO;
//    [self.timer invalidate];
}

- (void)countdown{
    
    self.remainingTime--;
    
    if (self.reload == YES) {
        
        [self.collectionView reloadData];
    }
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 100;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    LatestAnnouncedCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[LatestAnnouncedCell identifierStr] forIndexPath:indexPath];
    
    cell.time = self.remainingTime;
    
    return cell;
}

#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
}
*/

@end
